package gitlab_hook

import (
	"encoding/json"
	"fmt"
	"testing"
)

var noteData1 = `
{
    "object_kind": "note",
    "event_type": "note",
    "user": {
        "id": 5094,
        "name": "pan leiming",
        "username": "panleiming",
        "avatar_url": null,
        "email": "[REDACTED]"
    },
    "project_id": 20535,
    "project": {
        "id": 20535,
        "name": "Learn GitLab",
        "description": "Learn how to use GitLab to support your software development life cycle.",
        "web_url": "https://jihulab.com/lingxi/learn-gitlab",
        "avatar_url": "https://jihulab.com/uploads/-/system/project/avatar/20535/Artboard.jpg",
        "git_ssh_url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "git_http_url": "https://jihulab.com/lingxi/learn-gitlab.git",
        "namespace": "lingxi",
        "visibility_level": 0,
        "path_with_namespace": "lingxi/learn-gitlab",
        "default_branch": "master",
        "ci_config_path": "",
        "homepage": "https://jihulab.com/lingxi/learn-gitlab",
        "url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "ssh_url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "http_url": "https://jihulab.com/lingxi/learn-gitlab.git"
    },
    "object_attributes": {
        "attachment": null,
        "author_id": 5094,
        "change_position": null,
        "commit_id": null,
        "created_at": "2022-04-16 19:51:42 +0800",
        "discussion_id": "09b10d22ba8068415d2f592c5de6b7ac0017ac34",
        "id": 501035,
        "line_code": null,
        "note": "1111111111111111111111111",
        "noteable_id": 104672,
        "noteable_type": "Issue",
        "original_position": null,
        "position": null,
        "project_id": 20535,
        "resolved_at": null,
        "resolved_by_id": null,
        "resolved_by_push": null,
        "st_diff": null,
        "system": false,
        "type": null,
        "updated_at": "2022-04-16 19:51:42 +0800",
        "updated_by_id": null,
        "description": "1111111111111111111111111",
        "url": "https://jihulab.com/lingxi/learn-gitlab/-/issues/14#note_501035"
    },
    "repository": {
        "name": "Learn GitLab",
        "url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "description": "Learn how to use GitLab to support your software development life cycle.",
        "homepage": "https://jihulab.com/lingxi/learn-gitlab"
    },
    "issue": {
        "author_id": 5094,
        "closed_at": null,
        "confidential": false,
        "created_at": "2022-04-16 19:23:16 +0800",
        "description": "## Security dashboard\n\nGitLab can check your application for security vulnerabilities that may lead to unauthorized access, data leaks, denial of services, and more. GitLab reports vulnerabilities in the merge request so you can fix them before merging. The Security Dashboard provides a high-level view of any vulnerabilities detected in your projects, pipeline, and groups.\n \n* :book: [Read the security dashboard documentation](https://docs.gitlab.com/ee/user/application_security/security_dashboard/#gitlab-security-dashboard-security-center-and-vulnerability-reports)\n\n## Different type of security scans\n \n**GitLab offers you three types of security scans:**\n\n### Dependency scanning\nGitLab’s Dependency Scanning feature can automatically find security vulnerabilities in your dependencies while you’re developing and testing your applications. For example, dependency scanning lets you know if your application uses an external library that is known to be vulnerable.\n\n### Container scanning\nUse GitLab to audit your Docker-based apps. Your application’s Docker image may itself be based on Docker images that contain known vulnerabilities. Using GitLab, you can include an extra job in your pipeline that scans for those vulnerabilities and displays them in a merge request.\n\n### Dynamic Application Security Testing\nDynamic Application Security testing (D.A.S.T.) (note the final period) helps you automatically find security vulnerabilities in your running web applications while you’re developing and testing your applications. With DAST you can analyze your running web applications for known vulnerabilities. You can take advantage of DAST by either including the CI job in your existing  file or by implicitly using Auto DAST, provided by Auto DevOps.\n\n \n## Next steps\n* [ ] We recommend you use GitLab pipelines to run security scans. Don't have a pipeline yet? You can quickly set one up by navigating to **Project overview > Details** in your project, and click **Set up CI/CD**.\n* [ ] Add one of the security scan mentioned above in your by following the [quick start template](https://docs.gitlab.com/ee/user/application_security/index.html#quick-start).\n* [ ] Every time you push to this repository, a security scan will be triggered.\n* [ ] Navigate to **Security & Compliance > Security Dashboard** to view your vulnerability report.",
        "discussion_locked": null,
        "due_date": null,
        "id": 104672,
        "iid": 14,
        "last_edited_at": null,
        "last_edited_by_id": null,
        "milestone_id": null,
        "moved_to_id": null,
        "duplicated_to_id": null,
        "project_id": 20535,
        "relative_position": 7182,
        "state_id": 1,
        "time_estimate": 0,
        "title": "Set up security scans and use the security dashboard",
        "updated_at": "2022-04-16 19:51:42 +0800",
        "updated_by_id": null,
        "weight": null,
        "url": "https://jihulab.com/lingxi/learn-gitlab/-/issues/14",
        "total_time_spent": 0,
        "time_change": 0,
        "human_total_time_spent": null,
        "human_time_change": null,
        "human_time_estimate": null,
        "assignee_ids": [],
        "assignee_id": null,
        "labels": [
            {
                "id": 10773,
                "title": "30 day trial access",
                "color": "#6E49CB",
                "project_id": 20535,
                "created_at": "2022-04-16 19:23:15 +0800",
                "updated_at": "2022-04-16 19:23:15 +0800",
                "template": false,
                "description": null,
                "type": "ProjectLabel",
                "group_id": null
            },
            {
                "id": 10771,
                "title": "To do",
                "color": "#D9534F",
                "project_id": 20535,
                "created_at": "2022-04-16 19:23:15 +0800",
                "updated_at": "2022-04-16 19:23:15 +0800",
                "template": false,
                "description": null,
                "type": "ProjectLabel",
                "group_id": null
            }
        ],
        "state": "opened",
        "severity": "unknown"
    }
}
`

func TestCommentHook(t *testing.T) {
	hook := &CommentHook{}
	err := json.Unmarshal([]byte(noteData1), hook)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	data, _ := json.MarshalIndent(hook, "  ", "  ")
	fmt.Println(string(data))
}
